package me.luger.core.mvc.interceptor.appInfo;

import me.luger.core.mvc.WebService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * AppInfoInterceptor
 *
 * @author luger
 * @date 2016/12/8 0008
 */
@Component
public class AppInfoInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
        httpServletRequest.setAttribute("base", WebService.getProperty("app.base.url"));
        httpServletRequest.setAttribute("BASE_URL",WebService.getProperty("app.base.url"));
        httpServletRequest.setAttribute("IMG_BASE_URL",WebService.getProperty("img.base.url"));
        httpServletRequest.setAttribute("JS_BASE_URL",WebService.getProperty("js.base.url"));
        httpServletRequest.setAttribute("CSS_BASE_URL",WebService.getProperty("css.base.url"));
        httpServletRequest.setAttribute("test","luger_test");
    }

    @Override
    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {

    }
}
